package com.yssoft.service.core;

import com.yssoft.datasource.DataSource;
import com.yssoft.datasource.DataSourceContextHolder;
import com.yssoft.entity.core.TEnterprise;
import com.yssoft.entity.core.TcCompany;
import com.yssoft.mapper.core.TcCompanyMapper;
import com.yssoft.utils.UploadFile;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 鲁菊平
 * @time 2025/11/05 下午 13:52
 * @ 监管企业管理service
 */
@Service
@DataSource(DataSourceContextHolder.ORACLE)
public class CompanyServe {
    @Resource
    private TcCompanyMapper companyMapper;

    /**
     * 按许可证编号查询主体信息
     *
     * @param license
     * @return
     */
    public TcCompany queryCompanyInfoByLicense(String license) {
        return companyMapper.queryCompanyInfoLicense(license);
    }

    /**
     * 更新监管端主体信息
     *
     * @param enterprise
     * @return
     */
    public boolean updateCompany(TEnterprise enterprise) {
        //更新主体信息
        TcCompany company = new TcCompany();
        int result = 0;
        try {
            //获取主体信息
            TcCompany tcCompany = companyMapper.queryCompanyInfoLicense(enterprise.getSc());
            company.setId(tcCompany.getId());
            company.setFcpIssueDate(enterprise.getGrantDate());
            company.setFcpExpireDate(enterprise.getInvalidDate());
            company.setLicensePath(enterprise.getLicenseFile());
            company.setLicenseFileId(enterprise.getLicenseFileId());
            company.setIssueDate(enterprise.getIssueDate());
            company.setExpireDate(enterprise.getExpireDate());
            company.setPicPath(enterprise.getBusinessLicenseFile());
            company.setPicFileId(enterprise.getBusinessLicenseFileId());
             result = companyMapper.updateByPrimaryKeySelective(company);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return result > 0;
    }
}
